package www.openteam.com.model.business.other;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.PbProductInfo;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by kylin on 2016/11/25.
 */

public class SearchPbProductInfoModel extends BaseModel {

    private boolean isQuery = false;

    public boolean queryPbproductInfo(String name, int pageSize, final SearchPbProductInfoOnListener searchPbProductInfoOnListener) {

        httpApiService.queryPbproductInfo(name, pageSize)
                .compose(new CommonTransformer<PbProductInfo>())
                .subscribe(new CommonSubscriber<PbProductInfo>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(PbProductInfo pbProductInfo) {
                        isQuery = true;
                        searchPbProductInfoOnListener.queryPPISuccess(pbProductInfo);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        isQuery = false;
                        searchPbProductInfoOnListener.queryPPIFail(e);
                    }
                });
        return isQuery;

    }


    public interface SearchPbProductInfoOnListener {
        void queryPPISuccess(PbProductInfo pbProductInfo);

        void queryPPIFail(Throwable throwable);
    }
}
